<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <style>
        .container{
            padding: 20px;
            display: flex;
            flex-wrap: wrap;
        }
        .pic{
            width: 200px;
            height: 270px;
            margin-right: 30px;
        }
        .star{
            width: 16px;
            height: 16px;
        }
        text img{
            width: 30px;
            height: 30px;
        }
        .title{
            width: 200px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-size: 15px;
            margin: 5px 0;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="container">
            <div class="content" v-for="item of movies" :key="item.title">
                <img class="pic" :src="item.pic">
                <div class="title">{{item.title}}</div>
                <template v-for="value of item.star">
                    <img v-if="value>=1.5" src="images/star.png">
                    <img class="star" v-else-if="value>=1" src="images/ban-star.png">
                    <img v-else src="images/no-star.png">
                </template>
                <span>{{item.raiting}}</span>
            </div>
        </div>
        
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                movies:[]
            },
            mounted(){
                $.ajax({
                    url:'http://localhost:8000/top250'
                }).then(res=>{
                    var arr = res.result
                    arr.forEach(item=>{
                        item.star = this.transformStar(item.raiting)
                    })
                    this.movies = arr
                    console.log(res.result)
                })
            },
            methods:{
                transformStar(num){
                    var star = []
                    for(let i=0;i<5;i++){
                        if(num>2){
                            star.push(2)
                        }else if(num>0){
                            star.push(num)
                        }else{
                            star.num(0)
                        }
                        num=num-2;
                    }
                    return star
                }
            }
        })
    </script>
</body>
</html>